﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Mail;
using System.Text;
using System.Threading.Tasks;

namespace TelecomGis.Helper.Helper
{
    public class EmailHelper
    {
        public void SendMail(int port, string MailFrom, string pass, string MailTo, string Sbject, string Body, string host, List<MailAddress> listMailBcc)
        {
            SmtpClient smtp = new SmtpClient();
            smtp.Port = port;
            smtp.Host = host;
            smtp.UseDefaultCredentials = false;
            smtp.EnableSsl = true;
            smtp.UseDefaultCredentials = false;
            smtp.Credentials = new NetworkCredential(MailFrom, pass);
            MailMessage mail = new MailMessage(MailFrom, MailTo);
            mail.Subject = Sbject;
            mail.Body = Body;
            if (listMailBcc != null)
            {
                foreach (var item in listMailBcc)
                {
                    mail.Bcc.Add(item);
                }
            }
            mail.IsBodyHtml = true;
            try
            {
                smtp.Send(mail);
            }
            catch (Exception ex)
            {
                ex.ToString();
            }
        }
    }
}
